﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using XMLGener.Utils;

namespace XMLGener.Data
{
    /// <summary>
    /// 
    /// </summary>
    public class XSettings
    {
        private static XmlDocument settingsDocument = null;

        private static bool settingsLoaded = false;

        /// <summary>
        /// Function, which must be called at program start to initialize
        /// and load settings.
        /// </summary>
        public static void loadSettings()
        {
            if (!settingsLoaded)
            {
                settingsLoaded = true;
                string filename = DirectoriesUtil.combinePath(DirectoriesUtil.currentDir.FullName, "setting.xml");
                XSettings.loadSettings(filename);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        public static void loadSettings(string filename )
        {
            try
            {
                settingsDocument = new XmlDocument();
                settingsDocument.Load(filename);
                XmlElement docElement = settingsDocument.DocumentElement;
                XmlElement defTypes= XMLUtils.getSubElement(docElement,"defaultTypes");
                XMLGenerDataTypes.loadBaseDataTypes(defTypes);

            }catch(Exception e)
            {
                XLogger.addError("XSettings", "Loading setting document:" + e.Message);
                return;
            }
        }

    }
}
